/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PV112;

import com.jogamp.opengl.util.texture.Texture;
import javax.media.opengl.GL2;
import javax.vecmath.Point3f;

/**
 *
 * @author Erik
 */
public class Box {
    
    private Point3f center = new Point3f(0f, 0f, 0f);
    private int index;
    private boolean dragged;
    private FallThread ft = new FallThread();
    private Texture texture;

    public Box() {
    }

    public Box(int index, Point3f ctr) {
        this.index = index;
        this.center = ctr;
    }
    
    public void animateFall(){
        //float init = center.y;
        //center.y = .5f;
        ft.setHeight(center.y);
        ft.setBox(this);
        Thread t = new Thread(ft);
        t.start();
        //center.y = ft.getHeight();
    }
    
    public void animateStick(){}
    
    public void renderCube(GL2 gl){
        texture.bind(gl);
        gl.glLoadIdentity();
        gl.glTranslatef(center.x, center.y, center.z);
        gl.glBegin(GL2.GL_QUADS);
        gl.glNormal3f(0f, 1f, 0f);
        gl.glTexCoord2f(1, 1);
        gl.glVertex3f(0.5f, 0.5f, 0.5f);
        gl.glTexCoord2f(1, 0);
        gl.glVertex3f(0.5f, 0.5f, -0.5f);
        gl.glTexCoord2f(0, 0);
        gl.glVertex3f(-0.5f, 0.5f, -0.5f);
        gl.glTexCoord2f(0, 1);
        gl.glVertex3f(-0.5f, 0.5f, 0.5f);

        gl.glNormal3f(1f, 0f, 0f);
        gl.glTexCoord2f(1, 1);
        gl.glVertex3f(0.5f, 0.5f, 0.5f);
        gl.glTexCoord2f(1, 0);
        gl.glVertex3f(0.5f, 0.5f, -0.5f);
        gl.glTexCoord2f(0, 0);
        gl.glVertex3f(0.5f, -0.5f, -0.5f);
        gl.glTexCoord2f(0, 1);
        gl.glVertex3f(0.5f, -0.5f, 0.5f);

        
        gl.glNormal3f(0f, 0f, 1f);
        gl.glTexCoord2f(1, 1);
        gl.glVertex3f(0.5f, 0.5f, 0.5f);
        gl.glTexCoord2f(0, 1);
        gl.glVertex3f(-0.5f, 0.5f, 0.5f);
        gl.glTexCoord2f(0, 0);
        gl.glVertex3f(-0.5f, -0.5f, 0.5f);
        gl.glTexCoord2f(1, 0);
        gl.glVertex3f(0.5f, -0.5f, 0.5f);

        gl.glNormal3f(-1f, 0f, 0f);
        gl.glTexCoord2f(1, 1);
        gl.glVertex3f(-0.5f, 0.5f, 0.5f);
        gl.glTexCoord2f(1, 0);
        gl.glVertex3f(-0.5f, 0.5f, -0.5f);
        gl.glTexCoord2f(0, 0);
        gl.glVertex3f(-0.5f, -0.5f, -0.5f);
        gl.glTexCoord2f(0, 1);
        gl.glVertex3f(-0.5f, -0.5f, 0.5f);

        gl.glNormal3f(0f, 0f, -1f);
        gl.glTexCoord2f(1, 1);
        gl.glVertex3f(0.5f, 0.5f, -0.5f);
        gl.glTexCoord2f(0, 1);
        gl.glVertex3f(-0.5f, 0.5f, -0.5f);
        gl.glTexCoord2f(0, 0);
        gl.glVertex3f(-0.5f, -0.5f, -0.5f);
        gl.glTexCoord2f(1, 0);
        gl.glVertex3f(0.5f, -0.5f, -0.5f);

        gl.glNormal3f(0f, -1f, 0f);
        gl.glTexCoord2f(1, 1);
        gl.glVertex3f(0.5f, -0.5f, 0.5f);
        gl.glTexCoord2f(0, 1);
        gl.glVertex3f(-0.5f, -0.5f, 0.5f);
        gl.glTexCoord2f(0, 0);
        gl.glVertex3f(-0.5f, -0.5f, -0.5f);
        gl.glTexCoord2f(1, 0);
        gl.glVertex3f(0.5f, -0.5f, -0.5f);
        gl.glEnd();
    }

    public Point3f getPosition() {
        return center;
    }

    public void setPosition(Point3f position) {
        this.center = position;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public boolean isDragged() {
        return dragged;
    }

    public void setTexture(Texture texture) {
        this.texture = texture;
    }
    
    public void setDragged(boolean dragged) {
        this.dragged = dragged;
    }

    public Point3f getCenter() {
        return center;
    }

    public void setCenter(Point3f center) {
        this.center = center;
    }
}
